<!DOCTYPE html>
<html>
  <body>
    <p>Service worker test page</p>

    <script type="text/javascript">
      "use strict";

      let swRegistration;

      async function registerServiceWorker() {
        const sw = navigator.serviceWorker;
        swRegistration = await sw.register("serviceworker.js");
        await sw.ready;

        // Wait until the page is controlled.
        if (!sw.controller) {
          await new Promise(resolve => {
            sw.addEventListener("controllerchange", function() {
              resolve();
            }, {once: true});
          })
        }
      }

      addEventListener("pagehide", (event) => {
        swRegistration?.unregister();
      });
    </script>
  </body>
</html>
